<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<#include "../commons/imports.html"/>
</head>
<body class="layui-layout-body">
	<div class="layui-layout layui-layout-admin">
		<#include "../commons/header.html"/> <#include
		"../commons/sider.html"/>
		<div class="layui-body">
			<fieldset class="layui-elem-field layui-field-title" style="margin-top: 3px;">
				<legend>令牌生成</legend>
			</fieldset>
			<table class="table table-hover">
				<tbody>
					<tr>
						<td width="100" style="padding: 5px 0;"></td>
						<td width="300">
							<a class="layui-btn layui-btn-mini" onclick="issueJwt()">
							<i class="layui-icon">&#xe642;</i> 签发令牌</a>
						</td>
					</tr>
				</tbody>
			</table>
			<blockquote class="layui-elem-quote">
				<div id="jwt_value_div" style="display: none;">
					
					<div class="layui-input-inline">
						JWT令牌（有效期10秒）：<textarea rows="3" cols="200" id="jwt_value" name="jwt" class="layui-textarea"></textarea>
					</div>
				</div>
			</blockquote>
			
			<fieldset class="layui-elem-field layui-field-title" style="margin-top: 3px;">
				<legend>API调用</legend>
			</fieldset>
			
			<a class="layui-btn layui-btn-mini" onclick="jwtPost('add')">
							<i class="layui-icon">&#xe642;</i> 请求API:add</a>
							<br><br>
			<a class="layui-btn layui-btn-mini" onclick="jwtPost('update')">
							<i class="layui-icon">&#xe642;</i> 请求API:update</a>
							<br><br>
			<a class="layui-btn layui-btn-mini" onclick="jwtGet('delete')">
							<i class="layui-icon">&#xe642;</i> 请求API:delete</a>
							<br><br>			

							如果您想测试未进行身份认证情况，不点击"签发令牌"直接点击测试方法。
							<br>
							delete api只有拥有role_admin角色的账号可以调用，如果您想测试权限不足的情况，请非切换其他账号或修改权限后测试
							<br>如果您想测试令牌过期失效的情况，点击"签发令牌"等待10秒后，点击测试方法。
			<!-- 内容主体区域 -->
		</div>
		<#include "../commons/footer.html"/>
	</div>
	<script type="text/javascript" src="${ctx}/assets/js/main.js"></script>
		<script>
		function issueJwt() {
			ajaxPost("${ctx}/stateless/issue_jwt",function(result) {
				if(result.respond == 1){
					var jwt = result.jwt;
					$("#jwt_value").val(jwt);
				}
			});
			$("#jwt_value_div").show();
		}
		
		
		function jwtPost(_apiName) {
			var jwt = $("#jwt_value").val();
			ajaxPost('${ctx}/stateless/jwt_post',{
				 apiName:_apiName
				,jwt:jwt
			},function(result) {
				if(result.respond==1){
					layer.alert(result.message,{icon:1, title:'成功'});
				}else{
					layer.alert(result.message,{icon:2, title:'失败'});
				}
			})
		}
		function jwtGet(_apiName) {
			var jwt = $("#jwt_value").val();
			ajaxPost('${ctx}/stateless/jwt_get',{
				 apiName:_apiName
				,jwt:jwt
			},function(result) {
				if(result.respond==1){
					layer.alert(result.message,{icon:1, title:'成功'});
				}else{
					layer.alert(result.message,{icon:2, title:'失败'});
				}
			})
		}	
	</script>
</body>
</html>